﻿@{
    Layout = null;
}
<!DOCTYPE html> 
<html>
    <head>
        <title>@Language.Get("注册")</title>
        @Html.Partial("commonMeta")
        <style type="text/css">
        	input::-webkit-input-placeholder, textarea::-webkit-input-placeholder {
			color: #7f7f7f;font-size:13px;
			}
			input:-moz-placeholder, textarea:-moz-placeholder {
			color:#7f7f7f;font-size:13px;
			}
			input::-moz-placeholder, textarea::-moz-placeholder {
			color:#7f7f7f;font-size:13px;
			}
			input:-ms-input-placeholder, textarea:-ms-input-placeholder {
			color:#7f7f7f;font-size:13px;
			}
        </style>
    </head>
    <body>
        <div class="views">
			<div class="view view-main">
				<div class="navbar">
					<div class="navbar-inner">
			            <header id="common_header">
			                <a class="menu_icon_box">
								<b class="back-btn"></b>
							</a>
			                <h2>@Language.Get("注册")</h2>
			            </header>
			        </div>
			    </div> 
				<div class="pages navbar-through toolbar-through">
		          	<div data-page="index" class="page">
				        <!--内容区-->
						<div class="page-content" id="app_no_header">
				             <ul id="regis-data" class="layout-box regis-box">
				                 <li>
				                     <em class="user-icon"></em>
				                     <input type="text" id="userName" class="input-box" placeholder="@Language.Get("账号设置")" required="required" autofocus="autofocus"/>
				                     <span class="u-error"></span>
				                 </li>
				                  <li>
				                     <em class="pwd-icon"></em>
				                     <input type="password" id="userPwd"class="input-box" placeholder="@Language.Get("设置你的密码")" required="required" autofocus="autofocus" />
				                      <span class="pwd-error"></span>
				                 </li>
				                <li>
				                     <em class="phone-icon"></em>
				                     <input type="tel" class="input-box" style="width:50%" id="mobile" required="required" autofocus="autofocus" placeholder="@Language.Get("请输入手机号码")" maxlength="11"/>
				                    <span class="m-error"></span>
				                 </li>


								 <li style="height: 42px">
									 <em class="phone-icon"></em>
									 <input type="tel" class="input-box" id="_smsCode" style="width:30%;float:left;" required="required" autofocus="autofocus" placeholder="@Language.Get("请输入短信验证码")" maxlength="11"/>
									 <input type="submit" value="验证码" class="sure-btn regis-btn" style="width:25%;float:left;height:36px;line-height: 30px;margin-top: 3px" id="code_btn"/>
									 <span class="code-error" style="display: inline-block;float: left;line-height: 38px;color: red"></span>
								 </li>


				                 <li>
				                     <em class="user-icon"></em>
				                     <input type="text" id="nickName" class="input-box" placeholder="@Language.Get("请输入公司简称")" required="required" autofocus="autofocus" />
				                     <span class="n-error"></span>
				                 </li>
				                 <li>
				                     <em class="user-icon"></em>
				                     <input type="text" id="companyName" class="input-box" placeholder="@Language.Get("输入公司全称")" autofocus="autofocus" />
				                     <span class="c-error"></span>
				                 </li>
				                 <li style="border-bottom: 1px solid #d5d5d5;">
				                     <em class="user-icon"></em>
				                     <input type="text" id="introducer" class="input-box" placeholder="@Language.Get("输入介绍人")" autofocus="autofocus" />
				                     <span class="i-error"></span>
				                 </li>
				             </ul>
				               <a href="#" class="sure-btn regis-btn" id="regis-btn">@Language.Get("注册")</a>
				             <div class="link-box">
				                 <a href="#" class="link-right" id="login_btn"><b>@Language.Get("已经注册")？</b>@Language.Get("登录")</a>
				             </div>
				             <div class="tip-box regis-tip-box">
				                 <div class="tip regis-tip">
				                     <p class="msg regis-msg"></p>
				                     <span class="colse-tip-btn">@Language.Get("确定")</span>
				                 </div>
				             </div>
				             <div class="tip-box regis-success-box">
				                 <div class="tip success-rgistip">
				                     <p class="msg success-msg">@Language.Get("感谢您的注册,你注册的账号暂时不能登录，待我们的团队审核过后即可使用，请留意短信通知!")</p>
				                     <span class="colse-tip-btn go-login" id="go-login">@Language.Get("去登录")</span>
				                 </div>
				             </div>
				        </div>
				    </div>
				 </div>
			 </div>
		</div>
    </body>
</html>
<script type="text/javascript">
	var dict=@Html.Raw(Language.GetDict());
</script>
<script src="~/Js/jquery.min.js"></script>
<script type="text/javascript" src="~/Js/framework/framework7.js"></script>
<script src="~/Js/jquery.cookie.js"></script>
<script src="~/js/ThemesColor.js?v=@Wholesaler.Common.Version.Get"></script>
<script src="~/js/whole.js?v=@Wholesaler.Common.Version.Get"></script>
<script src="~/Js/is_app.js?v=@Wholesaler.Common.Version.Get"></script>
<script>
	var APP=is_app();
    $(function () {
        var username = $("#userName").val();//获取用户名
        var pwd = $("#userPwd").val();//获取密码
        var mobile = $("#mobile").val();//获取手机号
        var nickname = $("#nickName").val();//获取昵称
        //点击返回，app调用back()
		$(".back-btn").on("click",function(){
			if(APP){
				YiYi_APP.back();
			}else{
				location.href="/customer/index";
			}
		});
        //账号设置的校验start
        $("#userName").blur(function () {
            nameIsExit();
        });


        var isname = false;
        //校验账号是否已被注册
        function nameIsExit() {
            if ($("#userName").val() == "") {//为空的话
                $(".u-error").html("<font color='red'>*</font>");
                isname = false;
            } else {
                $.ajax({
                    url: "/Customer/CustomerRegIsExist",//提交地址
                    type: "POST",//提交方式
                    data: "{'UserName':'" + $("#userName").val() + "'}",
                    async: false,
                    contentType: "application/json; charset=utf-8",
                    success: function (result) {
                        var _result = eval('(' + result + ')');//eval()解析单个json对象                    
                        if (_result['msgcode'] == false) {//已被注册
                            $(".u-error").html("<font color='red'>"+_("已注册")+"</font>");
                            isname = false;//账号的变量为false
                        } else {//未被注册
                            $(".u-error").html("<font color='red'></font>");
                            isname = true;
                        }
                    },
                    error: function (err) {
                        alert("err:" + err);
                    }
                });
            }
        }
        //账号的校验end


        //手机号的验证和未被注册start
        $("#mobile").blur(function () {
            phoneIsExit();
        });
        var isphone = false;
        function phoneIsExit() {
            if ($("#mobile").val() == "") {
                $(".m-error").html("<font color='red'>*</font>");
                isphone = false;
            }
            if (!$("#mobile").val().match(/^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1})|(19[0-9]{1}))+\d{8})$/)) {
                $(".m-error").html("<font color='red'>"+_("请正确输入手机号")+"</font>");
                isphone = false;
            } else {
                $.ajax({
                    url: "/Customer/CustomerRegIsExist",//提交地址
                    type: "POST",//提交方式
                    data: "{'Mobile':'" + $("#mobile").val() + "'}",
                    async: false,
                    contentType: "application/json; charset=utf-8",
                    success: function (result) {
                        var _result = eval('(' + result + ')');//eval()解析单个json对象                    
                        if (_result['msgcode'] == false) {
                            $(".m-error").html("<font color='red'>"+_("已注册")+"</font>");
                            $("#code_btn").attr("disabled","disabled");
                            isphone = false;
                        } else {
                            $(".m-error").html("<font color='red'></font>");
                            $("#code_btn").attr("disabled",false);
                            isphone = true;
                        }
                    },
                    error: function (err) {
                        alert("err:" + err);
                    }
                });
            }
        }
        //手机号的验证和未被注册end
        
        //公司简称验证start
        $("#nickName").blur(function () {
            isNickIsExit();
        });
        var isnick = false;
        function isNickIsExit() {
            if ($("#nickName").val() == "") {//为空的话
                $(".n-error").html("<font color='red'>*</font>");
                isnick = false;
            } else if($("#nickName").val().length>15){
            	$(".n-error").html("<font color='red'>请输入15个字符以内的公司简称</font>");
            	$("#nickName").focus();
            }
            else {
                $.ajax({
                    url: "/Customer/CustomerRegIsExist",//提交地址
                    type: "POST",//提交方式
                    data: "{'NickName':'" + $("#nickName").val() + "'}",
                    async: false,
                    contentType: "application/json; charset=utf-8",
                    success: function (result) {
                        var _result = eval('(' + result + ')');//eval()解析单个json对象                    
                        if (_result['msgcode'] == false) {//已被注册
                            $(".n-error").html("<font color='red'>"+_("已注册")+"</font>");
                            isnick = false;//账号的变量为false
                        } else {//未被注册
                            $(".n-error").html("<font color='red'></font>");
                            isnick = true;
                        }
                    },
                    error: function (err) {
                        alert("err:" + err);
                    }
                });
            }
        }
        //公司简称验证end


        //密码验证start
//        $("#userPwd").blur(function () {
//            isPwd();
//        });
//        var ispwd = false;
//        function isPwd() {
//            if ($("#userPwd").val() == "") {
//                $(".pwd-error").html("<font color='red'>*</font>");
//                ispwd = false;
//            } else {
//                ispwd = true;
//                $(".pwd-error").html("<font color='red'></font>");
//            }
//
//        }


		var isPwd=false;
		$("#userPwd").blur(function(){
            var regPwd = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$/;
            var pwdVal=$("#userPwd").val();
            if(!regPwd.test(pwdVal)){
                 myApp.alert("密码由6-16位字母、数字组成")
                ispwd =false;
            }else{
                ispwd = true;
			}
		})
        //密码验证end

        //JQ自定义一个函数  倒计时
		var getCodeTime;
        $.extend({
            "setTimeA":function(b) {
                if(parseInt(b)>1) {
                    var timeStart = parseInt(b) - 1;
                    $("#code_btn").val(timeStart+"s");//显示秒数
                    getCodeTime=setTimeout(function(){
                        $.setTimeA(timeStart);
                    },1000);
                }else{
                    $("#code_btn").attr("disabled",false);//按钮可用
                    $("#code_btn").val("获取验证码");
                }

            }
        });

		//获取手机验证码start
        $("#code_btn").on('click',function(){
            var submitJson={};
            var mobile = /^(13[0-9]{9})|(18[0-9]{9})|(14[0-9]{9})|(17[0-9]{9})|(15[0-9]{9})$/
            var mobileVal=$("#mobile").val();
            if(mobile.test(mobileVal)){
                submitJson.Tel=mobileVal;
                $("#code_btn").attr("disabled","disabled");
                //调用上面自定义的函数
                $.setTimeA(90);
            }else{
                $("#mobile_error").show();
                return false;
            }
            submitJson.code=0;
            $.ajax({
                type:"POST",
                url: "/Customer/ValidateCode",
                data: JSON.stringify(submitJson),
                contentType: "application/json; charset=utf-8",
                success: function (result) {
                    var res=JSON.parse(result);
                    if(res.msgcode==false){
                        alert(res.msginfo);
                        window.clearTimeout(getCodeTime);
                        $("#get_code").attr("disabled",false);//按钮可用
                        $("#get_code").val("获取验证码");
                    }else{
                        $("#mobile_error").hide();
                    }
                }
            });
        });
        //获取手机验证码end

            //点击注册按钮
            $("#regis-btn").click(function () {
                if (isname && isphone && isnick && ispwd) {//用户名、手机号、昵称和密码验证通过
                        CustomerRegister();//注册方法
                }else {
                    myApp.alert(_("请正确填写资料!"));
                }
            });

            //关闭登录错误提示按钮
            $(".colse-tip-btn").click(function () {
                $(".regis-tip-box").hide();
            });
            //登录，app调用back()
            $("#login_btn").on("click",function(){
            	if(APP){
            		YiYi_APP.back();
            	}else{
            		window.location.href = "/customer/index";
            	}
            });
            //去登录，app调用signIn();
            $("#go-login").click(function () {
            	if(APP){
            		var app_json={};
            		app_json.userId=$("#userName").val();
              		app_json.pwd=$("#userPwd").val();
              		app_json.type=1;
            		YiYi_APP.signIn(JSON.stringify(app_json));
            	}else{
            		window.location.href = "/customer/index";
            	}               
            });
        });
   //用户注册的方法
            function CustomerRegister() {
                var requestCustomer = {};
                requestCustomer.UserName = $("#userName").val(); //
                requestCustomer.UserPassword = $("#userPwd").val();
                requestCustomer.Mobile = $("#mobile").val();
                requestCustomer.NickName = $("#nickName").val();
                requestCustomer.CompanyName = $("#companyName").val();
                requestCustomer.Introducer = $("#introducer").val();
                requestCustomer.SmsCode=$("#_smsCode").val();
                $.ajax({
                    url: "/Customer/CustomerRegister",//提交地址
                    type: "POST",//提交方式
                    data: JSON.stringify(requestCustomer),
                    contentType: "application/json; charset=utf-8",
                    success: function (result) {
                        var _result = eval('(' + result + ')');//eval()解析单个json对象
                        //$(".register_form input[type=reset]").trigger("click");//清空form数据 8-30 关键 一定要放最前面
                        if (_result['msgcode'] == false) {
                           myApp.alert(_result['msginfo']);
                        } else {
                           myApp.alert(_("感谢您的注册,我们的团队会尽快与您取得联系，去登录！"),function(){
	                           	if(is_app()){
	                          		var app_json={};
	                          		app_json.result=true;
	                          		app_json.userId=$("#userName").val();
	                          		app_json.pwd=$("#userPwd").val();
	                          		app_json.type=1;
	                          		YiYi_APP.registerResult(JSON.stringify(app_json));
	                          	}else{
	                          		location.href="/customer/index";
	                          	}
                           });

                        }
                    },
                    error: function (err) {
                        alert("err:" + err);
                    }
                });
            }
</script>


